<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script>
		var arr = [2,6,8,9,4,5,3,56,23,7,1,96,8]

		var narr = [];
		var len = arr.length;

		function difun() {
			//var num = Math.floor(Math.random() * 10 + 0)

			for(var i = 0; i < len; i++) {
			
				narr.push(arr.splice(0 , i + 1))
							
			}

			console.log(narr)

			var leng = narr.length;
			for(var s = 0; s < leng; s++) {
				console.log(qiu(narr[s]))
			}
		}
		difun();

		function qiu(arr) {
			var num = 0;
			var alen = arr.length;

			if(arr.constructor == Array) {
				for(var i = 0; i < alen; i++) {

					var item = arr[i]
					//console.log(arr[i].constructor !== Array)
					if(item.constructor !== Array){
						num += qiu(item)
					}else {
						num += i 
					}

				}
			}else {
				num += arr;
			}
			return num;
		}


	</script>
</body>
</html>